<table id="list" class="scroll"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
<div id="fieldsDialog" title="Category Error">
	<p>
		<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
		Category not selected!<br />
		<b>Please select category for action!</b>
	</p>
</div>

<script type="text/javascript">
jQuery('#list').jqGrid({
	url:'/catalog/categories/list/format/json?q=tree',
	treeGrid: true,
	ExpandColumn : 'CATEGORIES_ID',
	datatype: 'json',
	mtype: 'GET',
	colNames:['Id', 'Title', 'Alias', 'Parent'],
	colModel :[
	  {name:'CATEGORIES_ID', index:'CATEGORIES_ID', sorttype:'int', key:true, width:50},
	  {name:'CATEGORIES_TITLE', index:'CATEGORIES_TITLE', editable:true, editrules:{required:true}},
	  {name:'CATEGORIES_ALIAS', index:'CATEGORIES_ALIAS', editable:true, editrules:{required:true}},
	  {name:'CATEGORIES_PARENTID', index:'CATEGORIES_PARENTID', hidden:true, editrules:{edithidden:true}, editable:true, edittype:'select', editoptions:{value:{<?php foreach ($this->cats as $id => $title) echo "{$id}:'{$title}',"; ?>}}}
	],
	pager: jQuery('#pager'),
	rowNum:20,
	rowList:[20, 40, 60, 80, 100, 150, 200],
	sortname: 'CATEGORIES_ID',
	sortorder: 'asc',
	viewrecords: true,
	caption: 'Categoies View',
	editurl: "/catalog/categories/edit",
	height:'auto',
	width:'700'
}).navGrid('#pager',{
	edit:true, add:true, del:true, search:true
}).navButtonAdd('#pager',{
	caption:"Groups",
	onClickButton: function(id) {
		var gr = jQuery("#list").getGridParam("selrow");
		if( gr != null ) {
			document.location.href = '/catalog/categorygroups/list/catid/' + gr;
		} else {
			$("#fieldsDialog").dialog('open');
		}
	},
	position:"last"
});

$("#fieldsDialog").dialog({
	bgiframe: true,
	modal: true,
	autoOpen: false,
	buttons: {
		Ok: function() {
			$(this).dialog('close');
		}
	}
});
</script>
